/*
 * Copyright (c) www.bugull.com
 */

package com.bugull.farm.app.server.handler;

import com.bugull.farm.app.server.processor.AppHeartbeatProcessor;
import com.bugull.farm.app.server.processor.AppJoinProcessor;
import com.bugull.farm.app.server.processor.AppSubsProcessor;
import com.bugull.farm.app.server.processor.ControlProcessor;
import com.bugull.farm.app.server.processor.DeviceOnlineProcessor;
import com.bugull.farm.app.server.processor.SoftVersionProcessor;
import com.bugull.farm.core.cache.PropertiesCache;
import com.bugull.farm.core.frame.structure.Frame;
import com.bugull.farm.core.handler.AbstractAppFrameHandler;
import com.bugull.farm.core.handler.Processor;

import io.netty.channel.ChannelHandlerContext;

/**
 *
 * @author Frank Wen(xbwen@hotmail.com)
 */
public class MyAppFrameHandler extends AbstractAppFrameHandler {
	
	private PropertiesCache props = PropertiesCache.getInstance();
    
    @Override
    protected void processFrame(ChannelHandlerContext ctx, Frame frame) throws Exception{
    	
        byte cmd = frame.getByte("cmd");
        Processor processor = null;
        if (cmd == props.getByte("cmd.app.join")) {
        	processor = new AppJoinProcessor();
        } else if (cmd == props.getByte("cmd.app.info")) {
        	processor = new DeviceOnlineProcessor();
        } else if (cmd == props.getByte("cmd.app.soft.version")) {
        	processor = new SoftVersionProcessor();
        } else if (cmd == props.getByte("cmd.app.subs")) {
        	processor = new AppSubsProcessor();
        }  else {
        	processor = new ControlProcessor();
        }
        processor.process(ctx, frame);
    }

}
